package com.rainbowBoot.utils;

import java.util.HashMap;

/**
 * 懒汉单例缓存
 * @author 小熊
 * @version1.0
 */
public class SingleCacheUtil {
    // 缓存对象
    private static SingleCacheUtil singleCacheUtil = new SingleCacheUtil();
    // 缓存
    private HashMap<String, Object> mapCache = new HashMap<String, Object>();
    private SingleCacheUtil() {}

    /**
     * 获取缓存
     * @return
     */
    public static SingleCacheUtil getSingleCacheUtil() {
        return singleCacheUtil;
    }

    /**
     * 设置缓存
     * @param key
     * @param value
     */
    public void setCache(String key, Object value) {
        mapCache.put(key, value);
    }

    /**
     * 取出缓存
     * @param key
     * @return
     */
    public Object getCache(String key) {
        return mapCache.get(key);
    }

    /**
     * 清空缓存
     */
    public void clearCache() {
        mapCache = new HashMap<String, Object>();
    }

    /**
     * 删除指定缓存
     * @param key
     */
    public void removeCache(String key) {
        mapCache.remove(key);
    }
}